package com.yanqu.road.entity.musicroom;

import com.yanqu.road.entity.FieldTypeAnnotation;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class MusicRoomRoutingBeauty {
    private int beautyId;
//    @FieldTypeAnnotation(desc = "当前舒适度")
    private long comfort;

//    @FieldTypeAnnotation(desc = "当前心情值")
    private long mood;

//    @FieldTypeAnnotation(desc = "当前饱食度")
    private long satiety;

//    @FieldTypeAnnotation(desc = "总舒适度")
    private long totalComfort;

//    @FieldTypeAnnotation(desc = "总心情值")
    private long totalMood;

//    @FieldTypeAnnotation(desc = "总饱食度")
    private long totalSatiety;
//    @FieldTypeAnnotation(desc = "入住时间")
    private long liveInTime;
//    @FieldTypeAnnotation(desc = "入住的宿舍id")
    private int liveInBuildId;
//    @FieldTypeAnnotation(desc = "最近一次结算时辰结束时间")
    private long lastTimerEndTime;
//    @FieldTypeAnnotation(desc = "行程列表类型1生活行程,2工作行程")
    private int scheduleListType;
//    @FieldTypeAnnotation(desc = "分配的行程")
    private List<Integer> scheduleList = new ArrayList<>();
//    @FieldTypeAnnotation(desc = "当前行程的建筑id")
    private int nowBuildingId;
//    @FieldTypeAnnotation(desc = "下一个行程的建筑id")
    private int nextBuildingId;

    private long totalAddComfort;
    private long totalAddMood;
    private long totalAddSatiety;
    private long totalReduceComfort;
    private long totalReduceMood;
    private long totalReduceSatiety;

    public MusicRoomRoutingBeauty(UserMusicRoomBeautyData beautyData) {
        this.beautyId = beautyData.getBeautyId();
        this.comfort = beautyData.getComfort();
        this.mood = beautyData.getMood();
        this.satiety = beautyData.getSatiety();
        this.totalComfort = beautyData.getTotalComfort();
        this.totalMood = beautyData.getTotalMood();
        this.totalSatiety = beautyData.getTotalSatiety();
        this.liveInTime = beautyData.getLiveInTime();
        this.liveInBuildId = beautyData.getLiveInBuildId();
        this.lastTimerEndTime = beautyData.getLastTimerEndTime();
        this.scheduleListType = beautyData.getScheduleListType();
        this.scheduleList = new ArrayList<>(beautyData.getScheduleList());
        this.nowBuildingId = beautyData.getNowBuildingId();
        this.nextBuildingId = beautyData.getNextBuildingId();
    }

    public int getBeautyId() {
        return beautyId;
    }

    public long getComfort() {
        return comfort;
    }

    public long getMood() {
        return mood;
    }

    public long getSatiety() {
        return satiety;
    }

    public long getTotalComfort() {
        return totalComfort;
    }

    public long getTotalMood() {
        return totalMood;
    }

    public long getTotalSatiety() {
        return totalSatiety;
    }

    public void setComfort(long comfort) {
        this.comfort = comfort;
    }

    public void setMood(long mood) {
        this.mood = mood;
    }

    public void setSatiety(long satiety) {
        this.satiety = satiety;
    }

    public void addComfort(long addValue) {
//        if (getComfort()  + addValue > getTotalComfort()) {
//            setComfort(getTotalComfort());
//        }else{
//            setComfort(getComfort() + addValue);
//        }
        //不能超过Long的最大值
        if (getComfort() > 0){
            if (Long.MAX_VALUE - getComfort() < addValue) {
                addValue = Long.MAX_VALUE - getComfort();
            }
        }

        setComfort(getComfort() + addValue);
        this.totalAddComfort += addValue;
    }

    public void reduceComfort(long reduceValue) {
//        if (reduceValue > getComfort())
//            reduceValue = getComfort();
        setComfort(getComfort() - reduceValue);
        this.totalReduceComfort += reduceValue;
    }

    public void addMood(long addValue) {
//        if (getMood() + addValue > getTotalMood()) {
//            setMood(getTotalMood());
//        }else{
//            setMood(getMood() + addValue);
//        }
        //不能超过Long的最大值
        if (getMood() > 0){
            if (Long.MAX_VALUE - getMood() < addValue) {
                addValue = Long.MAX_VALUE - getMood();
            }
        }
        setMood(getMood() + addValue);
        this.totalAddMood += addValue;
    }

    public void reduceMood(long reduceValue) {
//        if (reduceValue > getMood())
//            reduceValue = getMood();
        setMood(getMood() - reduceValue);
        this.totalReduceMood += reduceValue;
    }

    public void addSatiety(long addValue) {
//        if (getSatiety() + addValue > getTotalSatiety()) {
//            setSatiety(getTotalSatiety());
//        }else{
//            setSatiety(getSatiety() + addValue);
//        }
        //不能超过Long的最大值
        if (getSatiety() > 0){
            if (Long.MAX_VALUE - getSatiety() < addValue) {
                addValue = Long.MAX_VALUE - getSatiety();
            }
        }
        setSatiety(getSatiety() + addValue);
        this.totalAddSatiety += addValue;
    }

    public void reduceSatiety(long reduceValue) {
//        if (reduceValue > getSatiety())
//            reduceValue = getSatiety();
        setSatiety(getSatiety() - reduceValue);
        this.totalReduceSatiety += reduceValue;
    }

    public int getRemainComfortPercent() {
        int percent = BigDecimal.valueOf(getComfort() * 1000).divide(BigDecimal.valueOf(getTotalComfort()), 8, BigDecimal.ROUND_UP).setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
        return percent;
    }

    public int getRemainMoodPercent() {
        int percent = BigDecimal.valueOf(getMood() * 1000).divide(BigDecimal.valueOf(getTotalMood()), 8, BigDecimal.ROUND_UP).setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
        return percent;
    }

    public int getRemainSatietyPercent() {
        int percent = BigDecimal.valueOf(getSatiety() * 1000).divide(BigDecimal.valueOf(getTotalSatiety()), 8, BigDecimal.ROUND_UP).setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
        return percent;
    }

    public boolean isAnyOneAttrPercentLessThan(int checkPercent) {
        if (getRemainComfortPercent() < checkPercent)
            return true;
        if (getRemainMoodPercent() < checkPercent)
            return true;
        if (getRemainSatietyPercent() < checkPercent)
            return true;
        return false;
    }

    public boolean isAllAttrPercentMoreThen(int checkPercent) {
        if (getRemainComfortPercent() < checkPercent)
            return false;
        if (getRemainMoodPercent() < checkPercent)
            return false;
        if (getRemainSatietyPercent() < checkPercent)
            return false;
        return true;
    }

    public boolean isAnyOneAttrLessThenZero(){
        if (getComfort() <= 0)
            return true;
        if (getMood() <= 0)
            return true;
        if (getSatiety() <= 0)
            return true;
        return false;
    }

    public long getLiveInTime() {
        return liveInTime;
    }

    public void setLiveInTime(long liveInTime) {
        this.liveInTime = liveInTime;
    }

    public int getLiveInBuildId() {
        return liveInBuildId;
    }

    public void setLiveInBuildId(int liveInBuildId) {
        this.liveInBuildId = liveInBuildId;
    }

    public long getLastTimerEndTime() {
        return lastTimerEndTime;
    }

    public void setLastTimerEndTime(long lastTimerEndTime) {
        this.lastTimerEndTime = lastTimerEndTime;
    }

    public int getScheduleListType() {
        return scheduleListType;
    }

    public void setScheduleListType(int scheduleListType) {
        this.scheduleListType = scheduleListType;
    }

    public List<Integer> getScheduleList() {
        return scheduleList;
    }

    public void setScheduleList(List<Integer> scheduleList) {
        this.scheduleList = scheduleList;
    }

    public int getNowBuildingId() {
        return nowBuildingId;
    }

    public void setNowBuildingId(int nowBuildingId) {
        this.nowBuildingId = nowBuildingId;
    }

    public int getNextBuildingId() {
        return nextBuildingId;
    }

    public void setNextBuildingId(int nextBuildingId) {
        this.nextBuildingId = nextBuildingId;
    }

    public int getSchedule(int timeNumber) {
        if (scheduleList.isEmpty()) {
            return 0;
        }
        int index = timeNumber % scheduleList.size();
        if (index > 0) {
            index--;
        } else if (index == 0){
            index = scheduleList.size() - 1;
        }
        return scheduleList.get(index);
    }

    public long getTotalAddComfort() {
        return totalAddComfort;
    }

    public long getTotalAddMood() {
        return totalAddMood;
    }

    public long getTotalAddSatiety() {
        return totalAddSatiety;
    }

    public long getTotalReduceComfort() {
        return totalReduceComfort;
    }

    public long getTotalReduceMood() {
        return totalReduceMood;
    }

    public long getTotalReduceSatiety() {
        return totalReduceSatiety;
    }
}
